package com.wlts.wzy.UploadModule.controller;

import com.wlts.wzy.Result.Result;
import com.wlts.wzy.UploadModule.imageUtil.MultipartFileToFile;
import com.wlts.wzy.UploadModule.imageUtil.OSSClientUtil;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;

/**
 * <p>
 * 上传文件 前端控制器
 * </p>
 *
 * @author wuzhiyong
 * @since 2019-03-31
 */
@Api(tags = "文件上传")
@RestController
@RequestMapping("/UploadFileManager")
public class FileUploadController {

    @Autowired
    private OSSClientUtil ossClientUtil;


    @RequestMapping(value = "/UploadFileOSS", method = RequestMethod.POST)
    public Result<String> UploadFileOSS(@RequestBody MultipartFile file) throws Exception {
        System.out.println("上传图片是否为空：" + file.isEmpty());
        // 项目在容器中实际发布运行的根路径
        File target = MultipartFileToFile.multipartFileToFile(file);
        String head = ossClientUtil.updateHomeImage(target);//此处是调用上传服务接口
        MultipartFileToFile.delteTempFile(target);
        return Result.buildResult(head);

    }

    @RequestMapping(value = "/UploadFileOSSBase64", method = RequestMethod.POST)
    public Result<String> UploadFileOSSBase64(@RequestBody String file) throws Exception {
        String head = ossClientUtil.uploadHomeImageOSSBase64(file);//此处是调用上传服务接口
        return Result.buildResult(head);

    }


}

